var compare_retail_tax_up_forbid_discount = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"compare_retail_tax_or_cost_up_forbid_discount"}');

if (active_discount == 1) {
    var itemStoreJsonList = JSON.parse(item_store_json);
    var upForbidDiscountClubList = []
    itemStoreJsonList.forEach(function (itemStoreJson) {
        if (!isNull(trait_nbr) && trait_nbr == 'ALL') {
            var amount = itemStoreJson.amount
            if (discount_range === 'price' && itemStoreJson.price_type == 2) {
                if (!isNull(retail_tax) && retail_tax > amount) {
                    upForbidDiscountClubList.push(itemStoreJson.store_id)
                }
            } else if (discount_range === 'cost' && itemStoreJson.price_type == 3) {
                if (!isNull(cost) && cost > amount) {
                    upForbidDiscountClubList.push(itemStoreJson.store_id)
                }
            }
        } else if (!isNull(trait_nbr) && itemStoreJson.store_type == 1) {
            if (trait_store.containsKey(trait_nbr)) {
                var clubList = trait_store.get(trait_nbr)
                if (!isNull(clubList)) {
                    clubList.forEach(function (club) {
                        if (club == itemStoreJson.store_id) {
                            var amount = itemStoreJson.amount
                            if (discount_range === 'price' && itemStoreJson.price_type == 2) {
                                if (!isNull(retail_tax) && retail_tax > amount) {
                                    upForbidDiscountClubList.push(itemStoreJson.store_id)
                                }
                            } else if (discount_range === 'cost' && itemStoreJson.price_type == 3) {
                                if (!isNull(cost) && cost > amount) {
                                    upForbidDiscountClubList.push(itemStoreJson.store_id)
                                }
                            }
                        }
                    })
                }
            }
        } else if (!isNull(store_id)) {
            if (itemStoreJson.store_id == store_id && itemStoreJson.store_type == store_type) {
                var amount = itemStoreJson.amount
                if (discount_range === 'price' && itemStoreJson.price_type == 2) {
                    if (!isNull(retail_tax) && retail_tax > amount) {
                        upForbidDiscountClubList.push(itemStoreJson.store_id)
                    }
                } else if (discount_range === 'cost' && itemStoreJson.price_type == 3) {
                    if (!isNull(cost) && cost > amount) {
                        upForbidDiscountClubList.push(itemStoreJson.store_id)
                    }
                }
            }
        }
    })
    if (upForbidDiscountClubList.length > 0) {
        compare_retail_tax_up_forbid_discount.CODE = 2;
        compare_retail_tax_up_forbid_discount.ACTION = 'error';
        var msgType = '';
        if (discount_range == 'price') {
            msgType = '售价'
        } else {
            msgType = '成本'
        }
        compare_retail_tax_up_forbid_discount.MSG = '门店[' + upForbidDiscountClubList.join(',') + ']更新' + msgType + '高于原' + msgType + '不能填写补差';
    }
}
JSON.stringify(compare_retail_tax_up_forbid_discount);